const express = require("express")
const router = express.Router()
const Essay_control = require("../control/EssayControl")
const multer = require("multer")
const path = require("path")
//自定义存储
const storage = multer.diskStorage({
    //自定义存储位置
    destination: function (req, res, cb) {
        cb(null, 'public/images/essay')
    },
    //文件名字
    filename: function (req, file, cb) {
        const uniquFilename = Date.now() + '-' + Math.round(Math.random() * 1E9)
        //获取后缀
        const ext = path.extname(file.originalname)
        cb(null, uniquFilename + ext)
    }
})
const upload_img = multer({ storage: storage })
router.post('/', Essay_control.add_essay)
router.post('/upload', upload_img.single("file"), Essay_control.add_img)
router.get('/:id', Essay_control.get_list)
router.get('/one/:id', Essay_control.get_one)
router.put('/one', Essay_control.update_one)
router.delete('/one/:id', Essay_control.delete_one)
module.exports = router